package Demo06.Demo03;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.TreeSet;

public class Demo06_TranscordTest {
    public static void main(String[] args) {
        ArrayList<Demo06_TransRecord> list = new ArrayList<>();
        File file = new File("G:\\小超\\untitled1\\wenjianjia\\Test.txt");
        print(file,list);
        for (Demo06_TransRecord transRecord :list){
            System.out.println(transRecord);
        }
        getIn("000301",list);
        getMoney(list);
        sort(list);
    }
    public static  void print(File file,ArrayList<Demo06_TransRecord> list){
        String s = "";
        try(
            FileReader fr = new FileReader(file);
            BufferedReader br = new BufferedReader(fr);
        ) {
            while ((s=br.readLine()) != null) {
                String[] split = s.split("\\s+");
                Demo06_TransRecord tranRecord = new Demo06_TransRecord(split[0],split[1],split[2],Integer.parseInt(split[3]),split[4],split[5],Double.parseDouble(split[6]));//创建Transcord对象
                list.add(tranRecord);
            }
        } catch (Exception e) {
        }
    }
    public static  void getIn(String CustomerNumber,ArrayList<Demo06_TransRecord> list){
        for (Demo06_TransRecord transRecord :list){
           if (transRecord.getCustomerNumber()==CustomerNumber){
               System.out.println("交易明细"+transRecord);
           }
        }
    }
    public  static  void  getMoney(ArrayList<Demo06_TransRecord>list){
        double sum =0.0;
        for (Demo06_TransRecord transRecord :list){
            sum+=transRecord.getAmount();
        }
        System.out.println("total:   "+sum);
    }
    private  static void sort(ArrayList<Demo06_TransRecord> list){
        TreeSet<Demo06_TransRecord> set = new TreeSet<>(list);
        for (Demo06_TransRecord transRecord:set){
            System.out.println("排序后：    "+set);
        }
    }
    }

